namespace NUnitTests{
    using System;
    using Guia.Core;
    using Guia.Elements;
    using NUnit.Framework;
    using WpfTestApplication;

    /// <summary>
    /// Summary description for ListBoxTest
    /// </summary>
    [TestFixture]
    public class ListBoxTest : AbstractWindowTest
    {
        protected override Type TestWindowType()
        {
            return typeof(ListBoxTestWindow);
        }

        protected override string TestWindowName()
        {
            return "ListBoxTestWindow";
        }

        [Test]
        public void TestGetSelectedItem()
        {
            ListBox listBox = window.Get<ListBox>("listBoxTest");
            ListBoxItem[] selItems = listBox.SelectedItems;
            Assert.AreEqual(0, selItems.Length);
            listBox.GetItem("item 1").Select();
            selItems = listBox.SelectedItems;
            Assert.AreEqual(1, selItems.Length);
            Assert.AreEqual("item 1", selItems[0].TextValue);
        }

        [Test]
        public void TestGetItemsEmpty()
        {
            ListBox listBox = window.Get<ListBox>("listBoxEmpty");
            ListBoxItem[] items = listBox.Items;
            Assert.AreEqual(0, items.Length);
        }

        [Test]
        public void TestGetItems()
        {
            ListBox listBox = window.Get<ListBox>("listBoxTest");
            ListBoxItem[] items = listBox.Items;
            Assert.AreEqual(3,items.Length);
            Assert.AreEqual("item 1",items[0].TextValue);
            Assert.AreEqual("item 2", items[1].TextValue);
            Assert.AreEqual("item 3", items[2].TextValue);
        }

        [Test]
        public void TestContains()
        {
            ListBox listBox = window.Get<ListBox>("listBoxTest");
            Assert.IsTrue(listBox.Contains("item 1"));
            Assert.IsTrue(listBox.Contains("item 2"));
            Assert.IsTrue(listBox.Contains("item 3"));
            Assert.IsFalse(listBox.Contains("item 4"));
        }

        [Test]
        public void TestGetItem()
        {
            ListBox listBox = window.Get<ListBox>("listBoxTest");
            ComboBoxItem item = listBox.GetItem("item 3");
            Assert.IsNotNull(item);
            Assert.AreEqual("item 3",item.TextValue);
        }

        [Test,ExpectedException(typeof(ElementNotFoundException))]
        public void TestGetItemNotExisting()
        {
            ListBox listBox = window.Get<ListBox>("listBoxTest");
            ListBoxItem item = listBox.GetItem("item 4");
        }

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void TestGetItemWithNullValue()
        {
            ListBox listBox = window.Get<ListBox>("listBoxTest");
            ListBoxItem item = listBox.GetItem(null);
        }

        [Test]
        public void TestGetItemWithIndexer()
        {
            ListBox listBox = window.Get<ListBox>("listBoxTest");
            ComboBoxItem item = listBox["item 3"];
            Assert.IsNotNull(item);
            Assert.AreEqual("item 3", item.TextValue);
        }

        [Test, ExpectedException(typeof(ElementNotFoundException))]
        public void TestGetItemNotExistingWithIndexer()
        {
            ListBox listBox = window.Get<ListBox>("listBoxTest");
            ListBoxItem item = listBox["item 4"];
        }

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void TestGetItemWithIndexerNullValue()
        {
            ListBox listBox = window.Get<ListBox>("listBoxTest");
            ListBoxItem item = listBox[null];
        }

        [Test,ExpectedException(typeof(OperationNotSupportedException))]
        public void TestSelectItemFromDisabledListBox()
        {
            ListBox listBox = window.Get<ListBox>("listBoxDisabled");
            listBox["item 1"].Select();
        }

        [Test, ExpectedException(typeof(OperationNotSupportedException))]
        public void TestUnselectItemFromDisabledListBox()
        {
            ListBox listBox = window.Get<ListBox>("listBoxDisabled");
            listBox["item 1"].Unselect();
        }
    }
}
